{% extends "base.html" %}
{% block title %}用户列表{% endblock %}
{% block user %}用户列表{% endblock %}
{% block navbar %}{{ super() }}{% endblock %}
{% block styles %}{{ super() }}
<style>
    .progress {
        position: relative;
        top: 20%;
        transform: translateY(50%);
    }

    .progress span {
        position: absolute;
        display: block;
        width: 100%;
        color: black;
    }
</style>
{% endblock %}
{% block scripts %}{{ super() }}
<script>
    $(document).ready(function () {
        $('#dt').DataTable(
            {
                "autoWidth": true,
                "pageLength": 25,
                dom: '<"top"flipB<"clear">>rt<"bottom"ipB<"clear">>',
                "order": [[0, "asc"], [1, "asc"]]
            });
    });
</script>
{% endblock %}
{% block content %}
<div class="container">
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            {% include 'flash_message.html' %}
        </div>
        <h4 class="row page-header" style="text-align:center">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                负荷选项：
                <a class="btn btn-success"
                    href="{{ url_for('bp_partner.list_users', type='month', range=5, back=0) }}">未来5月</a>
                <a class="btn btn-info"
                    href="{{ url_for('bp_partner.list_users', type='week', range=5, back=0) }}">未来5周</a>
                <a class="btn btn-warning"
                    href="{{ url_for('bp_partner.list_users', type='day', range=15, back=0) }}">未来15天</a>
            </div>
        </h4>

        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <table id="dt" class="row-border hover compact" style="width:100%">
                <thead>
                    <tr>
                        <th>部门</th>
                        <th>工号</th>
                        <th>姓名</th>

                        {% for field in fields %}
                        <th>{{ field }}
                            {% if load_type == 'week' %}周{% elif load_type == 'month' %}月{% else %}日{% endif %}</th>
                        {% endfor %}
                        <th>操作</th>
                        <th>操作</th>
                        <th>操作</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for user in users %}
                    <tr>
                        <td>{{ user[3] }}</td>
                        <td>{{ user[1] }}</td>
                        <td><a href="{{ url_for('bp_partner.tasks', user_id=user[0]) }}"> {{ user[2] }} </td>

                        {% if user_loads.get(user[0]) %}
                        {% for _,v in user_loads.get(user[0]).items() %}
                        <td>
                            <div class="progress">
                                <div class="progress-bar
                                        {% if v < 30 %}
                                        progress-bar-success
                                        {% elif v < 60 %}
                                        progress-bar-info
                                        {% elif v < 90 %}
                                        progress-bar-warning
                                        {% else %}
                                        progress-bar-danger
                                        {% endif %}
                                        " role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"
                                    style="width: {{ v }}%;">
                                    {% if v %}
                                    <span style="color: #0c0c0c;"> {{ v }}% </span>
                                    {% endif %}
                                </div>
                            </div>
                        </td>
                        {% endfor %}
                        {%  else %}
                        {% for field in fields %}
                        <td>
                            <div class="progress">
                                <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0"
                                    aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
                                </div>
                            </div>
                        </td>
                        {% endfor %}
                        {% endif %}

                        <td><a href="{{ url_for('bp_partner.assign', user_id=user[0]) }}">给他分配任务</a></td>
                        <td><a href="{{ url_for('bp_partner.receive', user_id=user[0]) }}">他收到的任务</a></td>
                        <td><a href="{{ url_for('bp_partner.send', user_id=user[0]) }}">他发出的任务</a></td>
                        <td><a href="{{ url_for('bp_partner.calendar', user_id=user[0]) }}">查看他的日历</a></td>

                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}